home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Toolbox / GetDragHiliteColor / Source / Application.c next >
Encoding:
C/C++ Source or Header  |  1996-09-17  |  3.5 KB  |  181 lines  |  [TEXT/CWIE]

  1. //updates 8/96: Prefix.h added as prefix file for 68K and PPC MC projects; old
  2. //routine names changed; GetDragHiliteColor.ยต.rsrc created from Sample.r
  3.  
  4. #include <QuickDraw.h>
  5. #include <Dialogs.h>
  6. #include <Fonts.h>
  7. #include <Processes.h>
  8. #include <TextEdit.h>
  9. #include <Events.h>
  10. #include <Menus.h>
  11. #include <Memory.h>
  12. #include <Errors.h>
  13. #include <ToolUtils.h>
  14. #include <Resources.h>
  15.  
  16.  
  17. void InitApplication(void);
  18. void CreateNewWindow(void);
  19. void MainEventLoop(void);
  20. void MenuCommand(long whaHappened);
  21. void DoAboutBox(void);
  22.  
  23. void PreEventLoop(void);
  24. void PostEventLoop(void);
  25. pascal void DrawWindowContent(short, short, GDHandle, long);
  26. void DrawIt(WindowPtr win);
  27. void DoUpdate(WindowPtr thisWindow);
  28.  
  29. static Boolean gDone;
  30.  
  31.  
  32. /*-------------------------------------------------------------------------------------*/
  33.  
  34. void main()
  35. {
  36.  
  37.     InitApplication();
  38.     PreEventLoop();
  39.     MainEventLoop();
  40. }
  41.  
  42.  
  43. /*-------------------------------------------------------------------------------------*/
  44.  
  45. void InitApplication()
  46. {
  47.     Handle theMenu;
  48.  
  49.     // Toolbox initialization
  50.     MaxApplZone();
  51.     InitGraf(&qd.thePort);
  52.     InitFonts();
  53.     InitWindows();
  54.     InitMenus();
  55.     TEInit();
  56.     InitDialogs(nil);
  57.     InitCursor();
  58.     FlushEvents(0,everyEvent);
  59.     
  60.     // Application initialization
  61.     gDone = false;
  62.     
  63.     theMenu = GetNewMBar(128);
  64.     if ( theMenu == nil )
  65.         goto MenuStuffFailed;
  66.  
  67.     SetMenuBar(theMenu);
  68.     AppendResMenu(GetMenuHandle(128), 'DRVR');
  69.     DrawMenuBar();
  70.  
  71.     return;
  72.     
  73. MenuStuffFailed:
  74.     // If the menu stuff failed, something just ain't right (most likely some 
  75.     // resources are missing.
  76.     gDone = true;
  77.     return;
  78.  
  79. }
  80.  
  81.  
  82. /*-------------------------------------------------------------------------------------*/
  83.  
  84. void DoAboutBox()
  85. {
  86.     (void) Alert(128, nil);
  87. }
  88.  
  89.  
  90. /*-------------------------------------------------------------------------------------*/
  91.  
  92. void MainEventLoop()
  93. {
  94.     EventRecord        theEvent;
  95.     WindowPtr        thisWindow;
  96.     short            clickArea;
  97.     Rect            screenRect;
  98.     long            menuResult;
  99.     char            charCode;
  100.  
  101.     while ( !gDone )
  102.     {
  103.         if ( WaitNextEvent(everyEvent, &theEvent, 0, nil) )
  104.         {
  105.             switch (theEvent.what)
  106.             {
  107.                 case mouseDown:
  108.                     clickArea = FindWindow(theEvent.where, &thisWindow);
  109.                     
  110.                     if (clickArea == inDrag)
  111.                     {
  112.                         screenRect = (**GetGrayRgn()).rgnBBox;
  113.                         DragWindow(thisWindow, theEvent.where, &screenRect);
  114.                     }
  115.                     else if ( clickArea == inContent )
  116.                     {
  117.                         if ( thisWindow != FrontWindow() )
  118.                             SelectWindow(thisWindow);
  119.                     }
  120.                     else if (clickArea == inGoAway)
  121.                     {
  122.                         if ( TrackGoAway(thisWindow, theEvent.where) )
  123.                             gDone = true;
  124.                     }
  125.                     else if ( clickArea == inMenuBar ) 
  126.                     {
  127.                         menuResult = MenuSelect(theEvent.where);
  128.                         if ( (menuResult  >> 16) != 0 )
  129.                         {
  130.                             MenuCommand(menuResult);
  131.                             HiliteMenu(0);
  132.                         }
  133.                     }
  134.                     break;
  135.                 case keyDown:
  136.                     charCode = theEvent.message & charCodeMask;
  137.  
  138.                     if ( (theEvent.modifiers & cmdKey) != 0 ) 
  139.                     {    
  140.                         menuResult = MenuKey(charCode);
  141.                 
  142.                         if ( (menuResult  >> 16) != 0 )
  143.                             MenuCommand(menuResult);
  144.                             
  145.                     } 
  146.                     break;
  147.                 case updateEvt:
  148.                     thisWindow = (WindowPtr)theEvent.message;    
  149.                     DoUpdate(thisWindow);
  150.                 
  151.                     break;
  152.                 
  153.             }
  154.         }
  155.     }
  156. }
  157.  
  158.  
  159.  
  160. /*-------------------------------------------------------------------------------------*/
  161.  
  162. void MenuCommand(long whaHappened)
  163. {
  164.     short    menuID, menuItem;
  165.     
  166.     menuID = (whaHappened >> 16);
  167.     menuItem = (whaHappened & 0xFFFF);
  168.     
  169.     if ( menuID == 128 )
  170.     {
  171.         if ( menuItem == 1)
  172.             DoAboutBox();
  173.     }
  174.     else if ( menuID == 129 )
  175.     {
  176.         if (menuItem == 1)
  177.             gDone = true;
  178.     }
  179. }
  180.  
  181.